﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using Cisoft.YiWu.Model;
using Cisoft.YiWu.BLL;
using Cisoft.IntegrationSystem.Model;
using Cisoft.IntegrationSystem.BLL;

public partial class yiwutong_web_DoctorShow : WebUI.Page.BasePage
{
    public string rehospitalid = "";
    public string redepartmentid = "";
    public string iconUrl = "../images/images_20100205/icon_title1.gif";
    public string titleclas = "";

    private DoctorInfoMO amo = new DoctorInfoMO();
    private DoctorInfoBO abo = new DoctorInfoBO();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["hospitalid"] != null && Request.QueryString["hospitalid"] != "" && Request.QueryString["departmentid"] != null && Request.QueryString["departmentid"] != "" && Request.QueryString["doctorid"] != null && Request.QueryString["doctorid"] != "")
            {
                rehospitalid = Request.QueryString["hospitalid"].ToString().Replace("'", "");
                redepartmentid = Request.QueryString["departmentid"].ToString().Replace("'", "");
                lblHospitalID.Text = Request.QueryString["hospitalid"].ToString().Replace("'", "");

                lblDepartmentID.Text = Request.QueryString["departmentid"].ToString().Replace("'", "");
                lblDoctorID.Text = Request.QueryString["doctorid"].ToString().Replace("'", "");
                //lblHospitalName.Text = GetHospitalName(Request.QueryString["hospitalid"].ToString());

                //数据初始化
                BindData();
            }
            else
            {
                Response.Redirect("index.aspx");
            }
        }
    }

    #region 绑定数据
    private void BindData()
    {
        int id = GetDoctorQueryString();
        if (id > 0)
        {
            DataSet dsall = new DataSet();
            dsall = abo.GetModelAllInfo(id);

            amo = abo.GetModel(id);

            if (amo != null && dsall.Tables[0].Rows.Count > 0)
            {
                lblHospitalName.Text = dsall.Tables[0].Rows[0]["HI_HospitalName"].ToString();
                lblHospitalNamebig.Text = dsall.Tables[0].Rows[0]["HI_HospitalName"].ToString();

                lblDepartmentName.Text = dsall.Tables[0].Rows[0]["DI_DepartmentlName"].ToString();
                lblDepartmentNamebig.Text = dsall.Tables[0].Rows[0]["DI_DepartmentlName"].ToString();

                lblDoctorName.Text = amo.DT_DoctorName;
                lblDoctorNamebig.Text = amo.DT_DoctorName;
                //新逻辑，取出的二进制字符串数据转换为真正显示的字符串  20081024---gwh---
                string strmiddlestring = amo.DT_DoctorSummary.ToString();

                if (strmiddlestring != "")
                {
                    byte[] dd = Convert.FromBase64String(strmiddlestring); // <-- 将数据从数据库中取出 
                    lblshow.Text = System.Text.Encoding.UTF8.GetString(dd);
                }

                
                //PostList.InnerHtml = ShowHtmlforEnterpriseList();
            }
            else
            {
                PageError("不存在该医生！", "index.aspx", "点击返回重试", "");
            }
        }
        else
        {
            PageError("不存在该医生！", "index.aspx", "点击返回重试", "");
        }
    }
    #endregion

    #region 获取传入医院的编号
    private int GetHospitalQueryString()
    {
        int id = 0;
        if (string.IsNullOrEmpty(Request.QueryString["hospitalid"].ToString().Replace("'","")))
        {
            PageError("不存在该医院！", "index.aspx", "点击返回重试", "");
        }
        else
        {
            try
            {
                id = int.Parse(Request.QueryString["hospitalid"].ToString().Replace("'", ""));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return id;
    }
    #endregion

    #region 获取传入科室的编号
    private int GetDepartmentQueryString()
    {
        int id = 0;
        if (string.IsNullOrEmpty(Request.QueryString["departmentid"].ToString().Replace("'", "")))
        {
            PageError("不存在该科室！", "index.aspx", "点击返回重试", "");
        }
        else
        {
            try
            {
                id = int.Parse(Request.QueryString["departmentid"].ToString().Replace("'", ""));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return id;
    }
    #endregion

    #region 获取传入医生的编号
    private int GetDoctorQueryString()
    {
        int id = 0;
        if (string.IsNullOrEmpty(Request.QueryString["doctorid"].ToString().Replace("'", "")))
        {
            PageError("不存在该医生！", "index.aspx", "点击返回重试", "");
        }
        else
        {
            try
            {
                id = int.Parse(Request.QueryString["doctorid"].ToString().Replace("'", ""));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return id;
    }
    #endregion

    #region 全为数字
    public bool isnumber(string s)
    {
        int Flag = 0;
        char[] str = s.ToCharArray();
        for (int i = 0; i < str.Length; i++)
        {
            if (Char.IsNumber(str[i]))
            {
                Flag++;
            }
            else
            {
                Flag = -1;
                break;
            }
        }
        if (Flag > 0)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
    #endregion
}
